package com.my.user.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.my.user.entity.User;
import com.my.user.service.UserService;
import com.my.user.service.UserServiceImpl;

import util.entity.ApplicationInterface;


@WebServlet("/IfUser")
public class IfUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String userName=request.getParameter("name");
		User user=new User();
		user.setuName(userName);
		UserService us=new UserServiceImpl();
		boolean flag=us.selectOneName(user);
		ApplicationInterface api = new ApplicationInterface();
		if(flag){
			api.setData(-1);
		}else{
			api.setData(1);
		}
		api.setStatus(1);
		api.setMessage("1是成功的意思");
		api.setErrorCode(-1);
		api.setErrorInfo("没有错误信息");
		
		Gson gson = new GsonBuilder()
						//以后再处理
						.create();
		String json = gson.toJson(api);
		
		PrintWriter out = response.getWriter();
		out.print(json);

	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
